import VeeValidate, { Validator } from 'vee-validate'
// 进行验证信息的自定义
const dict = {
  custom: {
    name: {
      required: '名称不能为空',
      max: '名称长度过长'
    },
    account: {
      required: '用户名不能为空',
      max: '用户名长度过长'
    },
    password: {
      required: '密码不能为空',
      min: '密码长度不少于6位',
      max: '密码长度不超过64位'
    },
    repassword: {
      required: '密码确认不能为空',
      confirmed: '两次密码不一致'
    },
    template: {
      required: '告警模板名称不能为空'
    },
    rule_name: {
      required: '规则名称不能为空'
    },
    type: {
      required: '设备类型不能为空'
    },
    groups: {
      required: '告警分类不能为空'
    },
    time_range: {
      required: '开启时间段不能为空'
    },
    except_level: {
      required: '告警等级不能为空'
    },
    rule: {
      required: '规则内容不能为空'
    },
    classify: {
      required: '设备分类不能为空'
    },
    alarm_reason: {
      required: '告警原因不能为空'
    },
    handleType: {
      required: '建议处理方式不能为空'
    },
    watch: {
      required: '手表话术不能为空'
    },
    duty: {
      required: 'Duty屏话术不能为空'
    },
    group_name: {
      required: '用户组名称不能为空'
    },
    groupName: {
      required: '分组名不能为空'
    },
    group_role: {
      required: '用户组角色不能为空'
    },
    parent_group: {
      required: '上级组不能为空'
    },
    user_name: {
      required: '姓名不能为空'
    },
    psid: {
      required: 'PSID不能为空'
    },
    role_name: {
      required: '角色不能为空'
    },
    tem_id: {
      required: '模板编号不能为空'
    },
    tem_name: {
      required: '模板名称不能为空'
    },
    product_name: {
      required: '产品名称不能为空'
    },
    epqc_category_name: {
      required: 'EPQC品项名称不能为空'
    },

    // 餐厅配置
    brand: {
      required: '品牌不能为空'
    },
    model: {
      required: '型号不能为空'
    },
    dev_name: {
      required: '设备名称不能为空'
    },
    serial: {
      required: '序列号不能为空'
    },
    assets_encode: {
      required: '资产编码不能为空'
    },
    pos_num: {
      required: '位置编号不能为空'
    },
    lora_ip: {
      required: 'IP地址不能为空'
    },
    macOne: {
      required: '电脑版mac地址不能为空'
    },
    macLeft: {
      required: '电脑版mac地址-左不能为空'
    },
    macRight: {
      required: '电脑版mac地址-右不能为空'
    },
    macA: {
      required: 'mac地址A不能为空'
    },
    macB: {
      required: 'mac地址B不能为空'
    },
    lora_id: {
      required: 'LoRa ID不能为空'
    },
    ref_lora_id: {
      required: 'LoRa集中器不能为空'
    },
    instruction: {
      required: '显示指示不能为空'
    },
    start_temperature: {
      required: '启动温度不能为空'
    },
    end_temperature: {
      required: '停止温度不能为空'
    },
    defrost_interval: {
      required: '化霜间隔不能为空'
    },
    defrost_duration: {
      required: '化霜时长不能为空'
    },
    defrost_stop_temperature: {
      required: '化霜终止温度不能为空'
    },
    sunrise_after_close: {
      required: '日出延后关不能为空'
    },
    sunset_after_close: {
      required: '日落延后开不能为空'
    },
    longest_runtime: {
      required: '运行最长时长不能为空'
    },
    lengthen_time: {
      required: '延时时间不能为空'
    },
    runtime: {
      required: '运行时间不能为空'
    },
    interval_hour: {
      required: '间隔时长不能为空'
    },
    eject_smoke: {
      required: '排烟风机不能为空'
    },
    faf: {
      required: '补风机不能为空'
    },
    longitude: {
      required: '门店经度不能为空'
    },
    latitude: {
      required: '门店纬度不能为空'
    },
    illuminance_maximum: {
      required: '照度上限不能为空'
    },
    illuminance_minimum: {
      required: '照度下限不能为空'
    },
    outdoor_temperature_maximum: {
      required: '室外温度上限不能为空'
    },
    outdoor_temperature_minimum: {
      required: '室外温度下限不能为空'
    },
    CO2_maximum: {
      required: 'CO2浓度上限不能为空'
    },
    CO2_minimum: {
      required: 'CO2浓度下限不能为空'
    },
    excessive_season_maximum: {
      required: '过度季节比较值上限不能为空'
    },
    excessive_season_minimum: {
      required: '过度季节比较值下限不能为空'
    },
    mode_switch_maximum: {
      required: '模式切换上限不能为空'
    },
    mode_switch_minimum: {
      required: '模式切换下限不能为空'
    },
    season_judge_delay: {
      required: '季节判断延时不能为空'
    },
    control_mode_delay: {
      required: '控制模式延时不能为空'
    },
    interval_auto_switch: {
      required: '几日自动切换不能为空'
    },
    pattern: {
      required: '模式不能为空'
    },
    appiont: {
      required: '左右指定不能为空'
    },
    menu_name: {
      required: '烤箱品项名称不能为空'
    },
    epqc_category_code: {
      required: 'EPQC品项名称不能为空'
    },
    cooking_time: {
      required: '烹饪时间不能为空'
    },
    delay_time: {
      required: '延时时间不能为空'
    },
    // 后台接口获取命令 拼接required
    setDte_temperature: {
      required: '不能为空'
    },
    setDTime_time: {
      required: '不能为空'
    },
    setDInterval_interval: {
      required: '不能为空'
    },
    setTem_temperature: {
      required: '不能为空'
    },
    menus_name: {
      required: '菜单名称不能为空'
    },
    // ----炸锅更新
    // 基本信息
    program_name: {
      required: '程序名称不能为空'
    },
    timing_factor: {
      required: 'timingFactor不能为空'
    },
    hold_time: {
      required: 'holdTime不能为空'
    },
    filter_lock_out: {
      required: 'filterLockout不能为空'
    },
    cooking_number: {
      required: 'quantity不能为空'
    },
    // 步骤
    time: {
      required: '时间不能为空'
    },
    temperature: {
      required: '温度不能为空'
    },
    // delaytime: {
    //   required: 'DelayTime不能为空'
    // },
    no_need_psi: {
      required: 'NoNeedPSI不能为空'
    },
    // 告警
    alarm_name: {
      required: '告警名称不能为空'
    },
    alarm_time: {
      required: '告警时长不能为空'
    },

    alias: {
      required: '设备名称不能为空'
    },
    is_energy: {
      required: '是否为能源设备不能为空'
    }
  }
}

// 长度为4位数的 maxLength
Validator.extend('maxLength4', {
  getMessage: field => '最大字符长度为4',
  validate: value => value.length <= 4
})
// 长度为16位数的 maxLength
Validator.extend('maxLength16', {
  getMessage: field => '最大字符长度为16',
  validate: value => value.length <= 16
})
// 长度为30位数的 maxLength
Validator.extend('maxLength30', {
  getMessage: field => '最大字符长度为30',
  validate: value => value.length <= 30
})
// 长度为50位数的 maxLength
Validator.extend('maxLength50', {
  getMessage: field => '最大字符长度为50',
  validate: value => value.length <= 50
})
// 长度为100位数的 maxLength
Validator.extend('maxLength100', {
  getMessage: field => '最大字符长度为100',
  validate: value => value.length <= 100
})
// 长度为120位数的 maxLength
Validator.extend('maxLength120', {
  getMessage: field => '最大字符长度为120',
  validate: value => value.length <= 120
})
// 长度为128位数的 maxLength
Validator.extend('maxLength128', {
  getMessage: field => '最大字符长度为128',
  validate: value => value.length <= 128
})
// 长度为300位数的 maxLength
Validator.extend('maxLength300', {
  getMessage: field => '最大字符长度为300',
  validate: value => value.length <= 300
})
// 只允许数字
Validator.extend('onlyRule0', {
  getMessage: field => '只允许数字',
  validate: value => /^[0-9]+$/.test(value)
})
// 只允许数字、小数点和-
Validator.extend('onlyRule1', {
  getMessage: field => '只允许数字、小数点和"-"字符',
  validate: value => /^[0-9\.-]+$/.test(value)
})
// 只允许数字、小数点
Validator.extend('onlyRule2', {
  getMessage: field => '只允许数字、小数点和"-"字符',
  validate: value => /^[0-9\.]+$/.test(value)
})
// 只允许数字、英文字母、小数点和"-_"字符'
Validator.extend('onlyRule3', {
  getMessage: field => '只允许数字、英文字母".-:_"字符',
  validate: value => /^[a-zA-Z0-9\.:_-]+$/.test(value)
})
// 只允许数字、英文字母、小数点和"-_"字符'
Validator.extend('onlyRule4', {
  getMessage: field => '只允许数字、英文字母".-%_"字符',
  validate: value => /^[a-zA-Z0-9\.:_%-]+$/.test(value)
})
// 只允许正整数
Validator.extend('onlyRule5', {
  getMessage: field => '必须为正整数',
  validate: value => /^[1-9]\d*$/.test(value)
})
// 值小于60
Validator.extend('onlyRule6', {
  getMessage: field => '不能大于60',
  validate: value => parseFloat(value) <= 60
})
// 只允许数字、 英文字母、小 数点 和"-_"字 符'
Validator.extend('onlyRule7', {
  getMessage: field => '只允许中文数字、英文字母"-"字符',
  validate: value => /^[a-zA-Z0-9\u4e00-\u9fa5\-]+$/.test(value)
})
// 只允许数字 0 - 120
Validator.extend('onlyRule8', {
  getMessage: field => '只允许0至120之间数字',
  validate: value => /^(?:[0-9][0-9]?|1[01][0-9]|120)$/.test(value)
})
Validator.extend('phone', {
  getMessage: field => '请输入正确的手机号',
  validate: value => value.length === 11 && /[1][0-9]{10}/.test(value)
})

Validator.extend('specialCharacter', {
  getMessage: field => '存在特殊字符(只能是中文、英文或数字)',
  validate: value => /^[A-Za-z0-9\u4e00-\u9fa5]+$/.test(value)
})

Validator.extend('noChinese', {
  getMessage: field => '只能是数字和英文',
  validate: value => /^[A-Za-z0-9]+$/.test(value)
})

Validator.extend('nameLength', {
  getMessage: field => '长度过长',
  validate: value => value.length <= 100
})

Validator.extend('fireNameLength', {
  getMessage: field => '长度过长',
  validate: value => value.length <= 10
})

Validator.extend('remarkLength', {
  getMessage: field => '长度过长',
  validate: value => value.length <= 100
})

Validator.extend('onnumber', {
  getMessage: field => '只允许数字',
  validate: value => /^[0-9]+$/.test(value)
})

Validator.extend('onpsid', {
  getMessage: field => 'psid不存在',
  validate: value => value.length > 8
})

Validator.extend('filterLockout', {
  getMessage: field => `只能输入数字(1-99) 或者 “NO_FILTER” 或者 “COOL” `,
  validate: value => {
    if (isNaN(value)) {
      return ['NO_FILTER', 'COOL'].includes(value)
    } else {
      return value >= 1 && value <= 99
    }
  }
})

Validator.extend('cookingNumber', {
  getMessage: field => `只能输入数字(0-99) 或者 “USER_PROMPT” `,
  validate: value => {
    if (isNaN(value)) {
      return value === 'USER_PROMPT'
    } else {
      return value >= 0 && value <= 99
    }
  }
})

export const Config = {
  fieldsBagName: 'veefields'
}
Validator.localize('en', dict)
export default VeeValidate
